<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\dynamic\controller;

class AdminDynamicList extends \app\AdminRest
{
    protected $order_model;
    protected $model;
    protected $cap_info;
    protected $list_model;
    protected $commment_model;
    protected $thumbs_model;
    protected $config_model;
    public function __construct(\think\App $app)
    {
        parent::__construct($app);
        $this->model = new \app\massage\model\Coach();
        $this->order_model = new \app\massage\model\Order();
        $this->list_model = new \app\dynamic\model\DynamicList();
        $this->commment_model = new \app\dynamic\model\DynamicComment();
        $this->thumbs_model = new \app\dynamic\model\DynamicThumbs();
        $this->config_model = new \app\massage\model\MassageConfig();
    }
    public function dynamicList()
    {
        $input = $this->_param;
        $dis[] = ["a.uniacid", "=", $this->_uniacid];
        if(!empty($input["coach_name"])) {
            $dis[] = ["b.coach_name", "like", "%" . $input["coach_name"] . "%"];
        }
        if(!empty($input["start_time"]) && !empty($input["end_time"])) {
            $dis[] = ["a.create_time", "between", $input["start_time"] . "," . $input["end_time"]];
        }
        if(!empty($input["status"])) {
            $dis[] = ["a.status", "=", $input["status"]];
        } else {
            $dis[] = ["a.status", ">", -1];
        }
        $data = $this->list_model->adminDataList($dis, $input["limit"]);
        $list = ["all", "ing", "pass", "nopass"];
        $where = ["uniacid" => $this->_uniacid];
        foreach ($list as $k => $value) {
            if(!empty($k)) {
                $where["status"] = $k;
                $data[$value] = $this->list_model->where($where)->count();
            } else {
                $data[$value] = $this->list_model->where($where)->where("status", ">", -1)->count();
            }
        }
        return $this->success($data);
    }
    public function dynamicInfo()
    {
        $input = $this->_param;
        $dis = ["id" => $input["id"]];
        $data = $this->list_model->dataInfo($dis);
        if(empty($data)) {
            $this->errorMsg("动态被删除");
        }
        $data["coach_info"] = $this->model->where(["id" => $data["coach_id"]])->field("coach_name,work_img,is_work")->find();
        return $this->success($data);
    }
    public function dynamicDel()
    {
        $input = $this->_input;
        $res = $this->list_model->dataUpdate(["id" => $input["id"]], ["status" => -1]);
        return $this->success($res);
    }
    public function dynamicCheck()
    {
        $input = $this->_input;
        $dis = ["id" => $input["id"]];
        $input["check_time"] = time();
        $res = $this->list_model->dataUpdate($dis, $input);
        return $this->success($res);
    }
    public function dynamicTop()
    {
        $input = $this->_input;
        $dis = ["id" => $input["id"]];
        $res = $this->list_model->dataUpdate($dis, $input);
        return $this->success($res);
    }
    public function commentList()
    {
        $input = $this->_param;
        $dis[] = ["a.uniacid", "=", $this->_uniacid];
        if(!empty($input["status"])) {
            $dis[] = ["a.status", "=", $input["status"]];
        } else {
            $dis[] = ["a.status", ">", -1];
        }
        if(!empty($input["title"])) {
            $dis[] = ["c.title", "like", "%" . $input["title"] . "%"];
        }
        if(!empty($input["start_time"]) && !empty($input["end_time"])) {
            $dis[] = ["a.create_time", "between", $input["start_time"] . "," . $input["end_time"]];
        }
        if(!empty($input["user_name"])) {
            $dis[] = ["b.nickName", "like", "%" . $input["user_name"] . "%"];
        }
        $data = $this->commment_model->getCommentList($dis, $input["limit"]);
        $list = ["all", "ing", "pass", "nopass"];
        $where = ["uniacid" => $this->_uniacid];
        foreach ($list as $k => $value) {
            if(!empty($k)) {
                $where["status"] = $k;
                $data[$value] = $this->commment_model->where($where)->count();
            } else {
                $data[$value] = $this->commment_model->where($where)->where("status", ">", -1)->count();
            }
        }
        return $this->success($data);
    }
    public function commentCheck()
    {
        $input = $this->_input;
        $dis = ["id" => $input["id"]];
        $res = $this->commment_model->dataUpdate($dis, $input);
        return $this->success($res);
    }
    public function commentDel()
    {
        $input = $this->_input;
        $res = $this->commment_model->dataUpdate(["id" => $input["id"]], ["status" => -1]);
        return $this->success($res);
    }
}

?>